﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Pay.Data {
	public class ProductSkuMap
		: System.Data.Entity.ModelConfiguration.EntityTypeConfiguration<ProductSku> {
		public ProductSkuMap() {
			// table
			ToTable("mc_ProductSku");

			// keys
			HasKey(t => t.Id);

			// Properties
			Property(t => t.Id)
				.HasColumnName("Id")
				.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity)
				.IsRequired();
			Property(t => t.ProductId)
				.HasColumnName("ProductId")
				.IsRequired();
			Property(t => t.SkuPath)
				.HasColumnName("SkuPath")
				.HasMaxLength(200)
				.IsRequired();
			Property(t => t.SkuName)
				.HasColumnName("SkuName")
				.HasMaxLength(200)
				.IsOptional();
			Property(t => t.Stock)
				.HasColumnName("Stock")
				.IsRequired();
			Property(t => t.Price)
				.HasColumnName("Price")
				.HasPrecision(18, 2)
				.IsRequired();
            Property(t => t.CostPrice)
                .HasColumnName("CostPrice")
                .HasPrecision(18, 2)
                .IsRequired();
            // Relationships
            HasRequired(t => t.Product)
				.WithMany(t => t.ProductSkus)
				.HasForeignKey(d => d.ProductId)
				.WillCascadeOnDelete(false);
		}
	}
}
